<template>
  <div class="tabs-item-wrapper">
    <div class="filter-container tabs-filter-container">
      姓名：
      <el-input placeholder="请输入姓名" size="small"
                class="filter-item search-item" v-model="searchObj.name"/>
      身份证号：
      <el-input size="small" placeholder="请输入身份证号"
                class="filter-item search-item" v-model="searchObj.orgName"/>
      电话号码：
      <el-input size="small" placeholder="请输入电话号码"
                class="filter-item search-item" v-model="searchObj.phone"/>
      <el-button size="small" @click="search" class="filter-item" type="primary">
        查询
      </el-button>
      <el-button size="small" @click="reset" class="filter-item" type="primary">
        导出 
      </el-button>
      <!-- <el-button size="small" @click="reset" class="filter-item">
        重置
      </el-button> -->
    </div>
    <div class="item-table">
      <el-table
        stripe
        size="small"
        :data="tabItems"
        ref="table"
        style="width: 100%;"
        v-loading="tabLoading"
      >
        <el-table-column label="姓名" align="center"
          prop="test1"
        />
        <el-table-column label="电话号码" align="center"
          prop="test2"
        />
        <el-table-column label="身份证号" align="center"
          prop="test3"
        />
        <el-table-column label="人员类别" align="center"
          prop="test4"
          min-width="80px"
        />
        <el-table-column label="操作" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="updateItem(scope.row)">修改</el-button>
            <el-button
              size="mini"
              type="text"
              @click="deleteItem(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-box">
        <el-pagination
          :current-page="pagination.currentPage"
          :page-size="pagination.pageSize"
          :page-count="pagination.pageCount"
          layout="prev, pager, next, jumper"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <ManagerEdit 
      ref="edit"
      :dialog-visible="dialog.isVisible"
      @close="editClose"
      @success="editSuccess"
    />
  </div>
</template>

<script>
import ManagerEdit from '@/components/csmCom/OrgService/ManagerEdit.vue';
import {reqUrl1} from '@/http/apiUrls.js';
export default {
  name: 'CsmManager',
  components: { ManagerEdit },
  data() {
    return {
      // 编辑框
      dialog:{
        isVisible: false,
        type: 'edit'
      },
      tabLoading: false,
      tableKey: 0,
      pageItems: 10, // 每页查询条数
      pagination: {
        currentPage: 1, // 当前页
        pageSize: 10, // 每页显示条数
        pageCount: 1, // 总页数
      },
      tabItems: [{
        id: 1,
        test1: '李XX',
        test2: '13334560987',
        test3: '522****3433',
        test4: '超级管理员'
      },{
        id: 2,
        test1: '李XX',
        test2: '13334560987',
        test3: '522****3433',
        test4: '超级管理员'
      }],
      searchObj: {
        name: '',
        orgName: '',
        phone: ''
      },
    }
  },
  methods:{
    search(){
      console.log(this.searchObj);
      // this.getData(1, this.pageItems, this.searchObj)
    },
    reset(){
      this.searchObj = {
        name: '',
        orgName,
        timeRange: []
      }
      //  this.getData(1, this.pageItems, {})
    },
    getData(current , size, model){
      let requestData = {
        current,
        size,
        model
      }
      this.tabLoading = true;
      this.$postJson(reqUrl1, requestData).then(res => {
        this.tabLoading = false;
        if(res){
          const pagination = {
            currentPage: parseInt(res.current), // 当前页面号
            pageSize: parseInt(res.size), // 每页条目数
            pageCount: parseInt(res.pages), // 总页面数
          }
          this.pagination = pagination;
          this.tabItems = res.records;
        }
      })
    },
    async handleCurrentChange(val) {
      await this.getData(val, this.pageItems, this.searchObj)
    },
    updateItem(item){
      this.$refs.edit.setEditObj(item)
      this.dialog = {
        isVisible: true,
        type: 'edit'
      }
    },
    editClose() {
      this.dialog.isVisible = false;
    },
    editSuccess() {
      this.getData(1, this.pageItems, this.searchObj)
    },
    deleteItem(item){
      this.$confirm('是否删除该人员?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteUserSubmit(item)
      });
      console.log(item);
    },
    deleteUserSubmit(item){
      this.$message({
        type: 'success',
        message: '删除成功!'
      });
      // const requestData = {
      //   id: item.id
      // }
      // this.$postJson(reqUrl1, requestData).then(res => {
      //   if(res){
      //     this.$message({
      //       type: 'success',
      //       message: '删除成功!'
      //     });
      //     this.getData(1, this.pageItems, this.searchObj)
      //   }
      // })
    }
  }
}
</script>
<style lang="scss" scoped>
.tabs-item-wrapper{
  padding: 40px 0;
  // background-color: rgba(242, 242, 242, 1);
}

.tabs-filter-container{
  padding: 0 20px;
}

.item-table{
  padding: 0 20px;
  margin-top: 30px;
}

</style>